<template>
	<view class="addressOuter">
		<view class="noAddress" v-if="address.length === 0">
			<image src="../../static/images/kongdz.png" mode=""></image>
		</view>

		<view class="address" v-else>
			<view class="address_item" v-for="item in address" :key="item.id">
				<view class="address_l">
					<view class="address_l_t">
						{{item.name}}<text>{{item.mobile}}</text>
					</view>
					<view class="address_l_b">
						<text class="isDefaulted" v-if="item.is_def ===1">默认</text>
						{{item.address}}
					</view>
				</view>
				<view class="address_r">
					<image src="../../static/images/iconImg/fenxiang.png" mode=""></image>
				</view>
			</view>
		</view>

		<view class="footer" @click="gotoAddress">
			新增收货地址
		</view>
	</view>
</template>

<script>
	import {
		serviceApi
	} from '../../api/paiModule/home.js'
	export default {
		data() {
			return {
				address: []
			};
		},
		onShow() {
			this.getAddress()
		},
		methods: {
			// 获取地址
			async getAddress() {
				const {
					data: res
				} = await serviceApi({
					method: "user.getusership",
					token: uni.getStorageSync('token')
				})
				this.address = res.data
				console.log(this.address);
			},

			// 新增地址按钮
			gotoAddress() {
				uni.navigateTo({
					url: '/pages/addAddress/addAddress'
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	$H: 93.4vh;

	.addressOuter {
		height: $H;
		background-color: #f8f8f8;
		position: relative;

		.noAddress {
			width: 200px;
			height: 200px;
			position: absolute;
			left: 50%;
			top: 40%;
			transform: translate(-50%, -50%);

			image {
				width: 100%;
				height: 100%;

			}
		}

		.address {
			background-color: #fff;
			padding: 10px 10px 10px 10px;

			.address_item {
				display: flex;
				align-items: flex-start;
				justify-content: space-between;
				padding: 0 10px;
				margin-bottom: 20px;

				.address_l {
					.address_l_t {
						font-size: 14px;

						text {
							font-size: 12px;
							color: #888888;
							margin-left: 10px;
						}
					}

					.address_l_b {
						font-size: 12px;
						margin-top: 6px;

						.isDefaulted {
							background-color: #e85a3a;
							color: #fff;
							padding: 2px;
							margin-right: 6px;
						}
					}
				}

				.address_r {
					padding-right: 10px;

					image {
						width: 16px;
						height: 16px;
					}
				}

			}

		}

		.footer {
			height: 40px;
			background-color: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			text-align: center;
			line-height: 40px;
			font-size: 12px;
		}
	}
</style>